<?php
/**
 * Description of AccessControl
 *
 * @author Newton
 */
require_once 'Zend/Session.php';

class AccessControl {
    
    protected $session;
    protected $user;

    function __construct()
    {
        $this->session = new Zend_Session_Namespace('whutoj');
        $this->user = $this->session->user;
    }
    
    //是否登录
    public function isLogin()
    {
        if(isset($this->user))
            return true;
        else
            return false;
    }
    
    //得到当前用户
    public function getSession()
    {
        if(isset($this->user))
        {
            return $this->user; //若已登录返回 $user
        }
    }
    
    //是否管理员
    public function isAdmin()
    {
        if($this->isLogin())
            if($this->user->getAdmin())
                return true;
            else
                return false;
        else
            return false;
    }
    
    //指定用户是否为管理员
    public function isThisAmdin($user)
    {
        if ($user->getAdmin())
            return true;
        else
            return false;
    }
    
    //登录
    public function login($user)
    {
        $this->session->user = $user;
    }

    //注销
    public function logout()
    {
        $this->session->lock;
        unset($this->session->user);
        $this->session->unlock();
    }
}

?>
